/*
 * ArbolContextosPPMC.cpp
 *
 *  Created on: 29/04/2012
 *      Author: lucas
 */

#include "../hdr/ArbolContextosPPMC.h"
#include <stdio.h>
#include <string.h>

ArbolContextosPPMC::ArbolContextosPPMC() {

}

int ArbolContextosPPMC::procesarCaracter(unsigned char caracter,
		unsigned char* contexto, size_t orden) {
	return _procesarCaracter(&nodoOrden0, caracter, contexto, orden, 0);
}

ArbolContextosPPMC::~ArbolContextosPPMC() {
	
}

int ArbolContextosPPMC::_procesarCaracter(NodoContexto* nodo,
		unsigned char caracter, unsigned char* contexto, size_t orden,
		size_t profundidad) {
	NodoContexto* proximoNodo = NULL;
	if (profundidad < orden) {
		proximoNodo = nodo->getNodoContextoSuperior(
				contexto[orden - profundidad - 1]);
		if(_procesarCaracter(proximoNodo, caracter, contexto, orden,
				profundidad + 1) == 1)
			return 1;
	}
	ContextoPPMC* context = nodo->getContexto();
	// Acá hacer: return context -> emitirCaracter(caracter);
	// Debug
	unsigned char* aux = new unsigned char[profundidad + 1];
	aux[profundidad] = 0;
	for (unsigned int i = 0; i < profundidad; i++)
		aux[i] = contexto[orden - profundidad + i];
	printf("Procesa: (%s) '%c' - orden %d, punteroCtx: %p\n", aux, caracter,
			profundidad, context); // Debug
	delete[] aux;
	return 0;
}

